<style scoped>
	.container {
		padding: 0 30rpx;
		padding-top: 140rpx;
	}
	
</style>
<template>
	<view>
		<uni-nav-bar class="bold" left-icon="back" title="通行记录" fixed="true" shadow="false" @clickLeft="leftBack"></uni-nav-bar>
		<view class="container">
				<data-list class="data-list" ref="visitorMsgList"  style="width: 1200rpx;" @load="handleLoad" @refresh="handleRefresh">
				<uni-table stripe type emptyText=" ">
					    <uni-tr>
							<uni-th align="left" width="90">通行时间</uni-th>
					        <uni-th align="left">通行结果</uni-th>
					        <uni-th align="center" width="170">通行设备标识</uni-th></uni-th>
					    </uni-tr>
					    <uni-tr v-for="(visitorMsg, index) in visitorMsgList" :key="index">
						    <uni-td>{{visitorMsg.accessTime}}</uni-td>
						    <uni-td>{{visitorMsg.result}}</uni-td>
						    <uni-td>{{visitorMsg.uniqueDeviceIdentifier}}</uni-td>
					    </uni-tr>
					</uni-table>
				</data-list>
		</view>
	</view>
</template>

<script>
	import { leftBack } from '../../commom/js/utils.js';
	import { showAccessRecords } from '../../api/visitor.js';
	
	export default{
		data() {
			return {
				visitorMsgList: [],
				params: {
					size: 100000,
					current: 1
				}
			}
		},
		methods: {
			leftBack() {
				leftBack()
			},
			onSearch() {
			showAccessRecords(this.params).then(res => {
				let data = res.data;
				if(data.code === 0) {
					if(data.data.records.length !== 0) {
						this.visitorMsgList = data.data.records;
					} else {
						this.visitorMsgList = []
					}
				} else {
					uni.showToast({
						title: data.msg,
						icon: 'none'
					})
				}
			})
			},
						// 请求加载数据
			handleLoad(data, callback) {
			 // this.onSearch();
				setTimeout(() => {
					// let visitorMsgList = [];
					// for (var i = 0; i < 3; i++) {
					// 	visitorMsgList.push(i);
					// }
					// this.visitorMsgList = [...this.visitorMsgList, ...this.visitorMsgList];
					callback({ list: this.visitorMsgList, total: 3 });
			}, 1500)
			},
			// 模拟请求数据刷新
			handleRefresh(data, callback) {
			   this.onSearch();
				setTimeout(() => {
					// this.visitorMsgList = [];
					// for (var i = 0; i < 3; i++) {
					// 	this.visitorMsgList.push(i);
					// }
					callback({ list: this.visitorMsgList, total: 3 });
				}, 1500);
			},
		},
		mounted() {
			this.onSearch()
		},
	}
</script>

<style>
</style>
